
# ------------------Managers 进程间数据共享-----------------
# # Queue、Pipe 只实现了数据的互交并没有实现数据的共享
from multiprocessing import Manager,Process
import os
def fun(d,L,n):
    d[n]="1" # {"0": "1"}
    d["2"]="2" # {"0": "1","2":"2"}
    L.append(n)
    print('子进程进程号：%s, 字典id %s，列表id %s'%(os.getpid(),id(d),id(L)))
if __name__ == '__main__':
    with Manager() as manager:
        d = manager.dict()
        L = manager.list(range(9))
        for i in range(10):
            p = Process(target=fun,args=(d,L,i))
            p.start()
        p.join()
        print(d)
        print(L)
    print("所有任务都已经结束")
    # print(d)
    # print(L)
